package com.utility.project.controller;

import com.utility.project.common.base.R;
import com.utility.project.entity.YsExperienceRecord;
import com.utility.project.param.ExperienceParam;
import com.utility.project.service.IYsExperienceRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yangzhiguo
 * @date 2024-06-18
 * @description 
 */
@Api(tags = "用户使用次数接口设计")
@RestController
@RequestMapping("/ysExperienceRecord")
public class YsExperienceRecordController {

    @Resource
    private IYsExperienceRecordService ysExperienceRecordService;

    @ApiOperation("通过ID查询单条使用次数数据")
    @GetMapping("/queryById")
    public R queryById(@RequestParam("id")Long id){
        return R.ok(ysExperienceRecordService.getById(id));
    }

    @ApiOperation("新增会员使用次数记录")
    @PostMapping("/save")
    public R save(@RequestBody ExperienceParam param){
        Boolean res = ysExperienceRecordService.saveExperience(param);
        if(res) {
            return R.okWithMsg("会员使用次数保存成功");
        }else{
            return R.fail("会员体验次数保存失败");
        }
    }

    @ApiOperation("根据用户id查询使用次数记录明细")
    @GetMapping("/getByUserName")
    @ApiResponse(code = 200 , message = "通过ID查询会员信息成功", response = YsExperienceRecord.class)
    public R getByUserName(@RequestParam("username") @ApiParam("用户名，对应小程序openId") String username){
        List<YsExperienceRecord> res = ysExperienceRecordService.getByUserName(username);
        return R.ok(res);

    }
    
}
